Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[amp-experiment] Exposes isDismissed() method in AmpUserNotification #3832

Merged
merged 4 commits into from
Jul 1, 2016

Conversation

lannka
Copy link
Contributor

@lannka lannka commented Jun 29, 2016

Also makes the UserNotificationManager.get() to return a promise of AmpUserNotification object.

isDismissed() will later be used by amp-experiment to check if a notification has been dismissed before (consent has been accepted). If not, the experiment will not take effect on the current page view. Experiment should never wait for a consent on the current page view.

Needed by #1411

*/
get(id) {
this.managerReadyPromise_.then(() => {
if (this.win_.document.getElementById(id) == null) {
user.warn(TAG, `Did not find amp-user-notification element ${id}.`);
}
});
return this.getElementDeferById_(id).promise;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we had a bug here. Should this be returned inside the managerReadyPromise chain? @erwinmombay

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the code again, it shouldn't be a bug. although yes a bit weird. I don't think we need to be dependent on managerReady (viewer + dom ready) to return the promise (since that promise is resolved independently). this was really just to give the publisher dev a warning if they mistyped the notification "id". although you could argue as that being a user error instead of a warning and that we could move this dom scan to the url replacement code.

@lannka
Copy link
Contributor Author

lannka commented Jun 29, 2016

@erwinmombay NotificationInterface is never used. Should we remove it?

dev.error(TAG, 'Failed to read storage', reason);
return false;
})
.then(persistedValue => !!persistedValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move this into the previous promise block:

.then(storage => storage.get(this.storageKey_))
.then(value => !!value, reason => {
  dev.error(TAG); //...
  return false;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks

@cramforce cramforce removed their assignment Jun 30, 2016
}
return this.storagePromise_
.then(storage => storage.get(this.storageKey_))
.then(persistedValue => !!persistedValue, reason => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why we're doing the coercion here instead of the previous then success handler?

also prefer .catch for error handler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also prefer .catch for error handler.

I told him to combine since !!value can never throw, so no reason to create another promise in the chain to catch it and any previous rejections.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm i see why now. this lgtm.

@erwinmombay
Copy link
Member

@lannka lets keep NotificationInterface (it is used by AmpUserNotification) for its public API

}

/**
* Register an instance of `amp-user-notification`.
* @param {string} id
* @param {!UserNotification} userNotification
* @param {!AmpUserNotification} userNotification
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably should have been NotificationInterface in the first place.

@erwinmombay
Copy link
Member

just some typing requests and addition of the method signature to the interface. otherwise LGTM

@lannka lannka merged commit 214c591 into ampproject:master Jul 1, 2016
@lannka lannka deleted the is_dimissed branch July 1, 2016 19:09
jonasmattsson1 added a commit to widespace-os/amphtml that referenced this pull request Jul 5, 2016
* master: (236 commits)
  trim all the columns (ampproject#3894)
  Refactoring: Turn private custom element methods into functions. (ampproject#3882)
  Lower the load priority of ad shaped iframes. (ampproject#3863)
  JsDoc fix (ampproject#3892)
  Add screenshots for Opera to AMP Validator extension. (ampproject#3866)
  Fix renaming of generated JSCompiler_prototypeAlias variable. (ampproject#3887)
  fix typo in amp-sidebar.md (ampproject#3833)
  Validator Roll-up (ampproject#3885)
  [CryptoService] Leverage browser native Crypto API to hash strings. (ampproject#3850)
  Size update (ampproject#3883)
  copy amp-ad docs to builtins (ampproject#3879)
  move doc to extension (ampproject#3878)
  [amp-experiment] Exposes isDismissed() method in AmpUserNotification (ampproject#3832)
  fix action-impl warning on dist (ampproject#3867)
  Add params for microad (ampproject#3827)
  Fixed some A4A tests. (ampproject#3859)
  Updates to colanalytics vendor config for amp-analytics. (ampproject#3849)
  Changes to implement A4A (AMP ads for AMP pages) (ampproject#3534)
  Addresses comment left over from PR#3841 (ampproject#3853)
  Expose submit event with on=submit:el.action syntax. (ampproject#3739)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants